using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

/// <summary>
/// Summary description for UploadUtils
/// </summary>
public class UploadUtils
{
    public UploadUtils()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public static string GetSavePath(HttpServerUtility server, string originalFileName)
    {
        string path = @"UploadFile\";
        path += DateTime.Now.Year;
        path += @"\";
        path += DateTime.Now.Month;
        path += @"\";
        path += DateTime.Now.Day;
        path += @"\";


        string tmpPath = path + originalFileName;

        string fileFirst = System.IO.Path.GetFileNameWithoutExtension(originalFileName);
        string fileExtension = System.IO.Path.GetExtension(originalFileName);

        int i = 0;
        while (File.Exists(server.MapPath(tmpPath)) == true)
        {
            tmpPath = path + fileFirst + i + fileExtension;
            i++;
        }

        // path = ;
        if (Directory.Exists(server.MapPath(path)) == false)
        {
            Directory.CreateDirectory(server.MapPath(path));
        }

        return tmpPath;
    }
}
